package com.ciei.dpagm.controller;

import com.alibaba.fastjson.JSONObject;
import com.ciei.dpagm.common.controller.BaseController;
import com.ciei.dpagm.entity.Users;
import com.ciei.dpagm.service.DriverLibraryDirectoryService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author wangyan
 * @date 2023/05/08
 */
@RestController
@RequestMapping("driverLibraryDirectory")
public class DriverLibraryDirectoryController extends BaseController {

    @Autowired
    private DriverLibraryDirectoryService driverLibraryDirectoryService;

    @RequestMapping("loadTree")
    public JSONObject loadTree(@RequestBody JSONObject data) {
        return driverLibraryDirectoryService.loadTree(data);
    }

    @RequiresPermissions("driverLibraryManagement:driverLibrary:projectFileEdit")
    @RequestMapping("editDirectoryName")
    public JSONObject editDirectoryName(@RequestBody JSONObject data) {
        return driverLibraryDirectoryService.editDirectoryName(data);
    }

    @RequiresPermissions("driverLibraryManagement:driverLibrary:projectFileDel")
    @RequestMapping("delete")
    public JSONObject delete(@RequestBody JSONObject data) {
        return driverLibraryDirectoryService.delete(data);
    }

    @RequiresPermissions("driverLibraryManagement:driverLibrary:projectFileDownload")
    @RequestMapping("download")
    @ResponseBody
    public JSONObject download(@RequestBody JSONObject data, HttpServletResponse response){
        return driverLibraryDirectoryService.download(data,response);
    }

    @RequiresPermissions("driverLibraryManagement:driverLibrary:projectFileUploadFile")
    @RequestMapping("uploadFile")
    @ResponseBody
    public JSONObject uploadFile(@RequestBody JSONObject data) {
        Users currentUser = (Users) SecurityUtils.getSubject().getPrincipal();
        return driverLibraryDirectoryService.uploadFile(data,currentUser);
    }

    @RequiresPermissions("driverLibraryManagement:driverLibrary:projectFileUploadFolder")
    @RequestMapping("uploadFolder")
    @ResponseBody
    public JSONObject uploadFolder(@RequestBody JSONObject data) {
        Users currentUser = (Users) SecurityUtils.getSubject().getPrincipal();
        return driverLibraryDirectoryService.uploadFolder(data,currentUser);
    }

    @RequiresPermissions("driverLibraryManagement:driverLibrary:projectFileAddChildFolder")
    @RequestMapping("addFolder")
    @ResponseBody
    public JSONObject addFolder(@RequestBody JSONObject data) {
        return driverLibraryDirectoryService.addFolder(data);
    }
}
